package net.sky.oa.dao.system.impl;

import java.util.List;

import net.sky.oa.dao.SkyBaseDaoImpl;
import net.sky.oa.dao.system.SysDeptDao;
import net.sky.oa.model.SysDept;

import org.springframework.stereotype.Repository;

@SuppressWarnings("unchecked")
@Repository
public class SysDeptDaoImpl extends SkyBaseDaoImpl<SysDept> implements SysDeptDao {
	
	public SysDeptDaoImpl() {
		super.setPersistType(SysDept.class);
	}

	public List<SysDept> findAllDept() {
		String hql = "from SysDept s";
		return findByHql(hql);
	}
	
	public List<SysDept> findByParentId(Long parentId){
	    String hql = "from SysDept d where d.parent.id=?";
	    Object[] params = { parentId };
	    return findByHql(hql, params);
	}
	
	public List<SysDept> findByName(String name){
		String hql = "from SysDept d where d.name=?";
		Object[] params = { name };
		return findByHql(hql, params);
	}
	
	public List<SysDept> listDept() {
		String hql = "select new SysDept(s.id,s.name) from SysDept s where s.status=1 and s.id > 0";
		return findByHql(hql);
	}
}